public class test3_2 {
    public static void main(String[] args) {
        String s = "a", t = "aa";
        System.out.println(minWindow(s, t));
    }

    public static String minWindow(String ss, String tt) {
        String ret = "";
        int min = ss.length() + 1;
        char[] s = ss.toCharArray();
        char[] t = tt.toCharArray();


        int[] hash1 = new int[128];

        int kinds = 0;
        for (char c : t) {
            if(hash1[c ]==0){
                kinds++;
            }
            hash1[c ]++;
        }

        int[] hash2 = new int[128];

        for (int left = 0, right = 0, count = 0; right < ss.length(); right++) {
            char in = s[right];
            hash2[in]++;
            if (hash2[in ] == hash1[in ]) {
                count++;
            }
            while (count == kinds) {
                if (min > right - left + 1) {
                    ret = ss.substring(left, right + 1);
                    min = right - left + 1;
                }

                char out = s[left];
                if (hash2[out] == hash1[out ]) {
                    count--;
                }
                left++;
                hash2[out ]--;

            }
        }
        return ret;
    }
}
